package com.example.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

import com.example.myapp.R;

public class MoveView extends View {
    // 定义相关变量，一次是显示位置的 x,y 坐标
    public float bitmapX;
    public float bitmapY;

    public MoveView(Context context){
        super(context);
        // 设置图片的起始坐标
        bitmapX = 0;
        bitmapY = 200;
    }

    // 重写 View 类的 onDraw() 方法
    @Override
    protected void onDraw(Canvas canvas){
        super.onDraw(canvas);
        // create and example an Object Paint
        Paint paint = new Paint();
        // Create bit img by pic
        Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.flower);
        // the move object
        canvas.drawBitmap(bitmap, bitmapX, bitmapY, paint);
        if (bitmap.isRecycled()){
            bitmap.recycle();
        }
    }
}
